<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MTB CAT1 Peripheral driver library: Functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="IFXCYP_one-line.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">MTB CAT1 Peripheral driver library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__group__sysclk__calclk__funcs.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Functions<div class="ingroups"><a class="el" href="group__group__sysclk.html">SysClk       (System Clock)</a> &raquo; <a class="el" href="group__group__sysclk__calclk.html">Clock Measurement</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">General Description</h2>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga0a87e123411d5711344780ddfa492f37"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__group__sysclk__returns.html#gad6699a184e2e3c01433251b0981558f3">cy_en_sysclk_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sysclk__calclk__funcs.html#ga0a87e123411d5711344780ddfa492f37">Cy_SysClk_StartClkMeasurementCounters</a> (<a class="el" href="group__group__sysclk__calclk__enums.html#ga2cc68848e0c27f0d74f6d5919eac7b3b">cy_en_meas_clks_t</a> clock1, uint32_t count1, <a class="el" href="group__group__sysclk__calclk__enums.html#ga2cc68848e0c27f0d74f6d5919eac7b3b">cy_en_meas_clks_t</a> clock2)</td></tr>
<tr class="memdesc:ga0a87e123411d5711344780ddfa492f37"><td class="mdescLeft">&#160;</td><td class="mdescRight">Assigns clocks to the clock measurement counters, and starts counting.  <a href="#ga0a87e123411d5711344780ddfa492f37">More...</a><br /></td></tr>
<tr class="separator:ga0a87e123411d5711344780ddfa492f37"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga979f2ef437908618291bf3a935488412"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sysclk__calclk__funcs.html#ga979f2ef437908618291bf3a935488412">Cy_SysClk_ClkMeasurementCountersGetFreq</a> (bool measuredClock, uint32_t refClkFreq)</td></tr>
<tr class="memdesc:ga979f2ef437908618291bf3a935488412"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the frequency of the indicated measured clock (clock1 or clock2).  <a href="#ga979f2ef437908618291bf3a935488412">More...</a><br /></td></tr>
<tr class="separator:ga979f2ef437908618291bf3a935488412"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaab1d99baa3555bcbbde18bc24822d4b0"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sysclk__calclk__funcs.html#gaab1d99baa3555bcbbde18bc24822d4b0">Cy_SysClk_ClkMeasurementCountersDone</a> (void)</td></tr>
<tr class="memdesc:gaab1d99baa3555bcbbde18bc24822d4b0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Checks if clock measurement counting is done, that is, counter1 has counted down to zero.  <a href="#gaab1d99baa3555bcbbde18bc24822d4b0">More...</a><br /></td></tr>
<tr class="separator:gaab1d99baa3555bcbbde18bc24822d4b0"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga0a87e123411d5711344780ddfa492f37"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0a87e123411d5711344780ddfa492f37">&#9670;&nbsp;</a></span>Cy_SysClk_StartClkMeasurementCounters()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__group__sysclk__returns.html#gad6699a184e2e3c01433251b0981558f3">cy_en_sysclk_status_t</a> Cy_SysClk_StartClkMeasurementCounters </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__group__sysclk__calclk__enums.html#ga2cc68848e0c27f0d74f6d5919eac7b3b">cy_en_meas_clks_t</a>&#160;</td>
          <td class="paramname"><em>clock1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>count1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__group__sysclk__calclk__enums.html#ga2cc68848e0c27f0d74f6d5919eac7b3b">cy_en_meas_clks_t</a>&#160;</td>
          <td class="paramname"><em>clock2</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Assigns clocks to the clock measurement counters, and starts counting. </p>
<p>The counters let you measure a clock frequency using another clock as a reference. There are two counters.</p>
<ul>
<li>One counter (counter1), which is clocked by clock1, is loaded with an initial value and counts down to zero.</li>
<li>The second counter (counter2), which is clocked by clock2, counts up until the first counter reaches zero.</li>
</ul>
<p>Either clock1 or clock2 can be a reference clock; the other clock becomes the measured clock. The reference clock frequency is always known. <br />
After calling this function, call <a class="el" href="group__group__sysclk__calclk__funcs.html#gaab1d99baa3555bcbbde18bc24822d4b0">Cy_SysClk_ClkMeasurementCountersDone()</a> to determine when counting is done; that is, counter1 has counted down to zero. Then call <a class="el" href="group__group__sysclk__calclk__funcs.html#ga979f2ef437908618291bf3a935488412">Cy_SysClk_ClkMeasurementCountersGetFreq()</a> to calculate the frequency of the measured clock.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">clock1</td><td>The clock for counter1</td></tr>
    <tr><td class="paramname">count1</td><td>The initial value for counter1, from which counter1 counts down to zero.</td></tr>
    <tr><td class="paramname">clock2</td><td>The clock for counter2</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Error / status code: <br />
CY_SYSCLK_INVALID_STATE if already doing a measurement <br />
CY_SYSCLK_BAD_PARAM if invalid clock input parameter <br />
else CY_SYSCLK_SUCCESS CY_PRA_STATUS_* - For the PSoC 64 devices there are possible situations when function returns the PRA error status code <a class="el" href="group__group__pra__enums.html#ga60be13e12e82986f8c0d6c6a6d4f12c5">cy_en_pra_status_t</a> instead of <a class="el" href="group__group__sysclk__returns.html#gad6699a184e2e3c01433251b0981558f3">cy_en_sysclk_status_t</a>. This is because for PSoC 64 devices the function uses the PRA driver to change the protected registers. Refer to <a class="el" href="group__group__pra__enums.html#ga60be13e12e82986f8c0d6c6a6d4f12c5">cy_en_pra_status_t</a> for more details.</dd></dl>
<dl class="section note"><dt>Note</dt><dd>The counters are both 24-bit, so the maximum value of count1 is 0xFFFFFF. If clock2 frequency is greater than clock1, make sure that count1 is low enough that counter2 does not overflow before counter1 reaches zero. </dd>
<dd>
The time to complete a measurement is count1 / clock1 frequency. </dd>
<dd>
The clocks for both counters must have a nonzero frequency, or <a class="el" href="group__group__sysclk__calclk__funcs.html#ga979f2ef437908618291bf3a935488412">Cy_SysClk_ClkMeasurementCountersGetFreq()</a> incorrectly reports the result of the previous measurement. </dd>
<dd>
Do not enter a device low power mode (Sleep, Deep Sleep) while doing a measurement; the measured clock frequency may not be accurate.</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd><div class="fragment"><div class="line">    <span class="comment">/* Scenario: ILO frequency may be drifting. Measure the ILO frequency using</span></div><div class="line"><span class="comment">                 the clock measurement counters, with the IMO as the reference. */</span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define  IMO_FREQ       8000000UL   </span><span class="comment">/* 8 MHz IMO */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define  ILO_NOMINAL    32768UL     </span><span class="comment">/* 32.768 kHz ILO */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line">    <span class="comment">/* Start the ILO clock measurement using the IMO */</span></div><div class="line">    (void)<a class="code" href="group__group__sysclk__calclk__funcs.html#ga0a87e123411d5711344780ddfa492f37">Cy_SysClk_StartClkMeasurementCounters</a>(CY_SYSCLK_MEAS_CLK_ILO,     <span class="comment">/* Counter 1 clock  = ILO */</span></div><div class="line">                                                0x7FUL,                     <span class="comment">/* Counter 1 period = 128 */</span></div><div class="line">                                                CY_SYSCLK_MEAS_CLK_IMO);    <span class="comment">/* Counter 2 clock  = IMO */</span></div><div class="line">    <span class="comment">/* Wait for counter 1 to reach 0 */</span></div><div class="line">    <span class="keywordflow">while</span>(!<a class="code" href="group__group__sysclk__calclk__funcs.html#gaab1d99baa3555bcbbde18bc24822d4b0">Cy_SysClk_ClkMeasurementCountersDone</a>()){}</div><div class="line"></div><div class="line">    <span class="comment">/* Measure clock 1 with the IMO clock cycles (counter 2) */</span></div><div class="line">    uint32_t measuredFreq = <a class="code" href="group__group__sysclk__calclk__funcs.html#ga979f2ef437908618291bf3a935488412">Cy_SysClk_ClkMeasurementCountersGetFreq</a>(<span class="keyword">false</span>, IMO_FREQ);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span>(measuredFreq != ILO_NOMINAL)</div><div class="line">    {</div><div class="line">        <span class="comment">/* Take appropriate action such as trimming the ILO or changing the LFCLK source */</span></div><div class="line">    }</div></div><!-- fragment --></dd></dl>

</div>
</div>
<a id="ga979f2ef437908618291bf3a935488412"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga979f2ef437908618291bf3a935488412">&#9670;&nbsp;</a></span>Cy_SysClk_ClkMeasurementCountersGetFreq()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t Cy_SysClk_ClkMeasurementCountersGetFreq </td>
          <td>(</td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>measuredClock</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>refClkFreq</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the frequency of the indicated measured clock (clock1 or clock2). </p>
<ul>
<li>If clock1 is the measured clock, its frequency is: clock1 frequency = (count1 / count2) * clock2 frequency</li>
<li>If clock2 is the measured clock, its frequency is: clock2 frequency = (count2 / count1) * clock1 frequency</li>
</ul>
<p>Call this function only after counting is done; see <a class="el" href="group__group__sysclk__calclk__funcs.html#gaab1d99baa3555bcbbde18bc24822d4b0">Cy_SysClk_ClkMeasurementCountersDone()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">measuredClock</td><td>False (0) if the measured clock is clock1; true (1) if the measured clock is clock2.</td></tr>
    <tr><td class="paramname">refClkFreq</td><td>The reference clock frequency (clock1 or clock2).</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>The frequency of the measured clock, in Hz. </dd></dl>
<dl class="section warning"><dt>Warning</dt><dd>The function returns zero, if during measurement device was in the Deep Sleep or partially blocking flash operation occurred. It means that current measurement is not valid and you should call the <a class="el" href="group__group__sysclk__calclk__funcs.html#ga0a87e123411d5711344780ddfa492f37" title="Assigns clocks to the clock measurement counters, and starts counting. ">Cy_SysClk_StartClkMeasurementCounters()</a> function once again.</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd>Refer to the <a class="el" href="group__group__sysclk__calclk__funcs.html#ga0a87e123411d5711344780ddfa492f37" title="Assigns clocks to the clock measurement counters, and starts counting. ">Cy_SysClk_StartClkMeasurementCounters()</a> function usage. </dd></dl>

</div>
</div>
<a id="gaab1d99baa3555bcbbde18bc24822d4b0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaab1d99baa3555bcbbde18bc24822d4b0">&#9670;&nbsp;</a></span>Cy_SysClk_ClkMeasurementCountersDone()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Cy_SysClk_ClkMeasurementCountersDone </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Checks if clock measurement counting is done, that is, counter1 has counted down to zero. </p>
<p>Call <a class="el" href="group__group__sysclk__calclk__funcs.html#ga0a87e123411d5711344780ddfa492f37">Cy_SysClk_StartClkMeasurementCounters()</a> before calling this function.</p>
<dl class="section return"><dt>Returns</dt><dd>Status of calibration counters: <br />
true = done <br />
false = not done</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd>Refer to the <a class="el" href="group__group__sysclk__calclk__funcs.html#ga0a87e123411d5711344780ddfa492f37" title="Assigns clocks to the clock measurement counters, and starts counting. ">Cy_SysClk_StartClkMeasurementCounters()</a> function usage. </dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>MTB CAT1 Peripheral driver library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
-->
</body>
</html>
